package com.docker.sys.dic;

import com.docker.core.constant.APPIDConstant;
import com.docker.core.mvc.APPID;
import com.docker.core.mvc.Remark;
import com.docker.core.mvc.controller.BaseAPIController;
import com.jfinal.aop.Inject;
import com.jfinal.core.ActionKey;
import com.jfinal.kit.Okv;

/**
 * @Author: ldl
 * @Create: 2020/09/18 018 16:55
 */
@Remark("系统字典管理")
@APPID(APPIDConstant.dum_web)
public class DicController extends BaseAPIController {

    @Inject
    private DicService dicService;

    /**
     * @Param: []
     * @return: TODO
     * @Author: ldl
     * @Create: 2020/09/18 018 16:53
     */
    @Remark("字典列表")
    public void all() {
        Okv cond = Okv.create()
                .set("dic_code", getPara("dic_code"));
        renderAPISuccess(dicService.all(cond));
    }

    /**
     * @Param: []
     * @return: TODO
     * @Author: ldl
     * @Create: 2020/09/18 018 16:55
     */
    @Remark("同步至缓存")
    public void cache() {
        renderAPI(dicService.cache());
    }

    @Remark("新增字典")
    public void save() {
        renderAPI(dicService.save(getBean(DicBean.class, ""), getUserId()));
    }

    @Remark("修改字典")
    public void update() {
        renderAPI(dicService.update(getBean(DicBean.class, ""), getUserId()));
    }

    @Remark("启用字典类型")
    public void enable() {
        renderAPI(dicService.update(getPara("dic_id"), "1", getUserId()));
    }

    @Remark("停用字典类型")
    public void disable() {
        renderAPI(dicService.update(getPara("dic_id"), "0", getUserId()));
    }

    // =================================================================================

    @Remark("性别字典")
    public void sex() {
        renderAPISuccess(dicService.child(DicConstant.user_sex));
    }

    @Remark("平台代码")
    @ActionKey("/api/sys/dic/restrict/platform")
    public void restrictPlatform() {
        renderAPISuccess(dicService.child(DicConstant.platform_code));
    }

    @Remark("用户类型")
    @ActionKey("/api/sys/dic/user/type")
    public void userType() {
        renderAPISuccess(dicService.child(DicConstant.user_type));
    }

    @Remark("编码类型")
    public void charset() {
        renderAPISuccess(dicService.child(DicConstant.charset));
    }

}
